using SmartLink.DTOS;
using SmartLink.DTOS.Permission;
using SmartLink.DTOS.SysBasic;
using SmartLink.RedisRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SmartLink.Infrastructure.Cache
{
    /// <summary>
    /// 角色权限缓存
    /// </summary>
    public static class RolePermissionCache
    {
        private const string _redisKeyPre = RedisKeyPre.RoleDataPermission;

        public static bool Set(int roleId, IList<PermissionListItemDTO> model)
        {
            return RedisManager.GetInstance().StringSetAsync(_redisKeyPre + roleId, model.SerializeObject());
        }

        public static IList<PermissionListItemDTO> Get(int roleId)
        {
            string json = RedisManager.GetInstance().StringGetAsync(_redisKeyPre + roleId);
            return string.IsNullOrEmpty(json) ? null : JsonEx.DeserializeObject<IList<PermissionListItemDTO>>(json);
        }
    }
}